home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / stdwin.zoo / vt / vtvtrm.c < prev   
Encoding:
C/C++ Source or Header  |  1989-10-17  |  2.5 KB  |  138 lines

  1. /* VTRM implementation using VT as lower layer.
  2.    Unfortunately, this isn't too useful on the input part:
  3.    you'll really want to use wgetevent directly to get access
  4.    to mouse clicks, menu events etc.
  5.    Another problem is that there is no portable way to direct normal
  6.    output (e.g., from printf and putchar) to the VTRM window.
  7.    One other thing: you'll have to call wdone() when you really exit. */
  8. /* $Header$ */
  9.  
  10. #include "vtimpl.h"
  11. #include "vtrm.h"
  12.  
  13. static VT *vt;
  14. static bool active;
  15.  
  16. int
  17. trmstart(rows_return, cols_return, flags_return)
  18.     int *rows_return, *cols_return, *flags_return;
  19. {
  20.     if (active)
  21.         return TE_TWICE; /* Already started */
  22.     if (vt == NULL) {
  23.         winit();
  24.         wsetdefwinsize(24*wcharwidth('0'), 80*wlineheight());
  25.         vt= vtopen("VTRM", 24, 80);
  26.         if (vt == NULL)
  27.             return TE_NOMEM; /* Failure */
  28.     }
  29.     *rows_return= 24;
  30.     *cols_return= 80;
  31.     *flags_return=
  32.         HAS_STANDOUT | CAN_SCROLL | CAN_SENSE;
  33.     return TE_OK;
  34. }
  35.  
  36. trmend()
  37. {
  38.     active= FALSE;
  39. }
  40.  
  41. trmputdata(row, col, data)
  42.     int row, col;
  43.     char *data;
  44. {
  45.     char *start= data;
  46.     int mask= 0;
  47.     vtsetcursor(vt, row, col);
  48.     do {
  49.         if ((*data & 0x80) != mask) {
  50.             if (data > start) {
  51.                 if (mask) {
  52.                     char *p;
  53.                     for (p= start; p < data; ++p)
  54.                         *p &= 0x7f;
  55.                     wsetinverse();
  56.                 }
  57.                 vtputstring(vt, start, data-start);
  58.                 if (mask) {
  59.                     char *p;
  60.                     for (p= start; p < data; ++p)
  61.                         *p |= 0x80;
  62.                     wsetplain();
  63.                 }
  64.                 start= data;
  65.             }
  66.             mask= *data & 0x80;
  67.         }
  68.     } while (*data++ != EOS);
  69.     vteolclear(vt);
  70. }
  71.  
  72. trmscrollup(r1, r2, n)
  73.     int r1, r2;
  74.     int n;
  75. {
  76.     if (n > 0)
  77.         vtscrollup(vt, r1, r2+1, n);
  78.     else if (n < 0)
  79.         vtscrolldowm(vt, r1, r2+1, -n);
  80. }
  81.  
  82. trmsync(row, col)
  83.     int row, col;
  84. {
  85.     vtsetcursor(vt, row, col);
  86. }
  87.  
  88. static lasth, lastv;
  89.  
  90. int
  91. trminput()
  92. {
  93.     EVENT e;
  94.     for (;;) {
  95.         switch (e.type) {
  96.         case WE_COMMAND:
  97.             switch (e.type) {
  98.             case WC_CANCEL:
  99.                 return '\003';
  100.             case WC_RETURN:
  101.                 return '\r';
  102.             case WC_TAB:
  103.                 return '\t';
  104.             case WC_BACKSPACE:
  105.                 return '\b';
  106.             case WC_LEFT:
  107.                 return '\034';
  108.             case WC_RIGHT:
  109.                 return '\035';
  110.             case WC_UP:
  111.                 return '\036';
  112.             case WC_DOWN:
  113.                 return '\037';
  114.             }
  115.             break;
  116.         case WE_CHAR:
  117.             return e.u.character;
  118.             break;
  119.         case WE_MOUSE_DOWN:
  120.         case WE_MOUSE_MOVE:
  121.         case WE_MOUSE_UP:
  122.             lasth= e.u.where.h;
  123.             lastv= e.u.where.v;
  124.             if (e.u.type == WE_MOUSE_UP)
  125.                 return '\007';
  126.             break;
  127.         }
  128.     }
  129. }
  130.  
  131. int
  132. trmsense(row_return, col_return)
  133.     int *row_return, *col_return;
  134. {
  135.     *row_return= lastv / vtcheight(vt);
  136.     *col_return= lasth / vtcwidth(vt);
  137. }
  138.